package com.hsf.cloudweb.utils;


import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class HibernateUtil {
    private static final SessionFactory sessionFactory = buildSessionFactory();

    private static SessionFactory buildSessionFactory(){
        //通过hibernate.cfg.xml配置文件创建数据库会话工厂 SessionFactory
        try {
            return new Configuration().configure().buildSessionFactory();
        } catch (Throwable ex) {
//            ex.printStackTrace();
            throw new ExceptionInInitializerError("initial SessionFactory creation failed."+ex);
        }
    }

    public static SessionFactory getSessionFactory(){
        return sessionFactory;
    }



}
